package com.ftwj.demo.modular.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.ftwj.demo.base.common.BaseDao;
import com.ftwj.demo.base.util.PageInfoBean;
import com.ftwj.demo.modular.entity.NoticeBean;

/**
*
* <p>Title: NoticeDao</p>  
* <p>Description: 描述</p>
* <p>Copyright: Copyright (c) 2020 </p>  
* <p>Company: 兰州飞天网景信息产业有限公司</p>    
* @author WangSli
* @date 2020年04月10日 09:51:30
* @version V1.0
*/
@Repository
public class NoticeDao extends BaseDao<NoticeBean, Integer> {

	/**
	 * <p>Title: page</p>  
	 * <p>Description: 分页查询</p>  
	 * @param pageInfo
	 * @param type
	 * @param title
	 * @author HeYang
	 * @date 2020年4月13日  
	 * @version 1.0
	 */
	public PageInfoBean page(PageInfoBean pageInfo, Integer type, String title,Integer userId) {
		StringBuilder builder = new StringBuilder("SELECT n.*,u.update_time updateTime,u.state ustate FROM tb_notice n,tb_notice_user u WHERE n.notice_id = u.notice_id AND u.user_id = ? ");
		List<Object> list = new ArrayList<Object>();
		list.add(userId);
		if (type != null) {
			builder.append(" AND n.type = ? ");
			list.add(type);
		} 
		if (!StringUtils.isEmpty(title)) {
			builder.append(" AND n.title like ? ");
			list.add("%"+title+"%");
		}
		return jtl.page(builder.toString(), pageInfo, list.toArray());
	}
	

}
